<template>
	<view class="person-container">
		<ticket-item desc="去接单" v-if="ticketList.length" @detail="goTicketDetail" :ticketList="ticketList"></ticket-item>
		<view class="bgwhite" v-else>
			<van-empty description="暂无工单" />
		</view>
	</view>
</template>

<script>
	import dayjs from 'dayjs';
	import TicketItem from '@/components/ticketItem'
	export default {
		components: {
			TicketItem
		},
		data() {
			return {
				params: {
					工单状态: 'unclaimed',
					pagination: {
						current: 1,
						pageSize: 100
					},
					sorter: {
						field: "id",
						order: 0
					}
				},
				operatorList: [],
				typeList: [],
				haveMore: true,
				ticketType: this.$type.ticketType,
				ticketList: [],
				projectList: []
			}
		},
		// onReachBottom() {
		// 	if(this.haveMore){
		// 		this.getMoreTicketList()
		// 	}
		// },
		onLoad(options) {
			// this.params.所属单位 = +options.unitId
			// this.getTicketList()
		},
		onShow() {
			this.getTicketList()
		},
		methods: {
			getTicketList() {
				uni.showLoading({
					mask: true
				})
				this.projIds = uni.getStorageSync('userInfo').projectIds
				this.$http2.post('ticketSystem/ticket/list', this.params).then(res => {
					console.log(res)
					if (res.code === 10000) {
						if(res.data.list !== null) {
							res.data.list.forEach(item => {
								item.创建时间 = dayjs(item.创建时间).format('YYYY-MM-DD HH:mm:ss')
							})
							this.ticketList = res.data.list.filter(item => {
								return this.projIds.includes(item.所属项目)
							})
						}
					}
				})
			},
			getMoreTicket() {
				this.params.pagination.current++
				this.$http2.post('ticketSystem/ticket/list', this.params).then(res => {
					console.log(res, '加载更多')
					if (res.code === 10000) {
						if (res.data.list == null) {
							this.haveMore = false
							return
						}
						let list = res.data.list.filter(item => {
							return this.projectList.includes(item.所属项目)
						})
						this.ticketList.push(...list)
					}
				})
			},
			goTicketDetail(id) {
				uni.navigateTo({
					url: '../orderDetail/orderDetail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.person-container {
		background-color: #f5f6f7;
		height: 100vh;
	}
	.bgwhite {
		height: 100vh;
		background-color: #fff;
	}
</style>
